home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Ken Long / NewBounce-c / original < prev   
Encoding:
Text File  |  1994-12-04  |  3.1 KB  |  114 lines  |  [TEXT/R*ch]

  1. /* Written  1:17 pm  Jun 12, 1986 by sdh@joevax.UUCP in uiucdcsb:net.sources.mac */
  2. /* ---------- "Sleep Utility" ---------- */
  3. /*
  4. The following is the source to a sleep utility. It is equivalent to the
  5. blit demo bounce. It clears the *entire* screen to black thus allowing you
  6. to leave your mac on w/o having the menu bar burned in.
  7.  
  8. #include <quickdraw.h>
  9. #include <event.h>
  10. */
  11. #define range 12;
  12. #define size 32 /*should be a power of 2*/
  13. #define boundx 511
  14. #define boundy 341
  15.  
  16. GrafPort myPort;
  17.  
  18. int x1[size], x2[size], y1[size], y2[size], dx1, dx2, dy1, dy2;
  19.  
  20.  
  21. /* Bounce - Steve Hawley 6/13/86 Written in Aztec C V 1.06H */
  22.  
  23. /* This is a Mac implementation of the bounce program written for
  24.    the BLIT and 5620 terminals. It simply keeps track of a list of
  25.    end points of lines, erasing the oldest and replacing it with 
  26.    one derived from the newest plus some dx and dy values */
  27.  
  28.  
  29. abs(i)
  30. register int i;
  31. {
  32.  
  33.     /* absolute value */
  34.     if (i < 0) return -i;
  35.     else return i;
  36. }
  37.  
  38. init()
  39. {
  40.     int i;
  41.     
  42.     dx1 = Random() % range + 4; /* create random dx's and dy's */
  43.     dx2 = Random() % range + 4;
  44.     dy1 = Random() % range + 4;
  45.     dy2 = Random() % range + 4;
  46.     
  47.     x1[0] = abs(Random() % boundx) + 1; /* create first point */
  48.     x2[0] = abs(Random() % boundx) + 1;
  49.     y1[0] = abs(Random() % boundy) + 1;
  50.     y2[0] = abs(Random() % boundy) + 1;
  51.     
  52.     MoveTo(x1[0], y1[0]);
  53.     LineTo(x2[0], y2[0]); /* draw it */
  54.     
  55.     for (i=1; i< size; i++) {   /* derive the rest of the points */
  56.        if ( (x1[i-1] + dx1 < 0) || (x1[i-1] + dx1 > boundx))
  57.           dx1 = -dx1;
  58.        x1[i] = x1[i-1] + dx1;
  59.        if ( (x2[i-1] + dx2 < 0) || (x2[i-1] + dx2 > boundx))
  60.           dx2 = -dx2;
  61.        x2[i] = x2[i-1] + dx2;
  62.        if ( (y1[i-1] + dy1 < 0) || (y1[i-1] + dy1 > boundy))
  63.           dy1 = -dy1;
  64.        y1[i] = y1[i-1] + dy1;
  65.        if ( (y2[i-1] + dy2 < 0) || (y2[i-1] + dy2 > boundy))
  66.           dy2 = -dy2;
  67.        y2[i] = y2[i-1] + dy2;
  68.        MoveTo(x1[i], y1[i]); /* draw them */
  69.        LineTo(x2[i], y2[i]);
  70.     }
  71. }
  72.  
  73.  
  74. main ()
  75. {
  76.     Rect myRect;
  77.     register int i, j;
  78.  
  79.     InitGraf(&thePort);
  80.     OpenPort(&myPort); /* create my own port so I don't need */
  81.                    /* windows and can blacken the whole screen */
  82.     
  83.     HideCursor();
  84.     SetRect(&myRect, 0, 0, boundx+1, boundy+1);
  85.     PenPat(black);
  86.     PaintRect(&myRect); /* clear screen to black */
  87.     PenMode(patXor); /* use exclusive-or drawing to ease animation */
  88.     init();
  89.     i = 0; /* oldest set of points */
  90.     while(!Button()) { /* repeat until button is down */
  91.        j = i-1;  /* find newest points */
  92.        if (j< 0) j = size - 1;
  93.        MoveTo(x1[i], y1[i]); /* erase old */
  94.        LineTo(x2[i], y2[i]);
  95.        /* derive new point */
  96.        if ( (x1[j] + dx1 < 0) || (x1[j] + dx1 > boundx))
  97.           dx1 = -dx1;
  98.        x1[i] = x1[j] + dx1;
  99.        if ( (x2[j] + dx2 < 0) || (x2[j] + dx2 > boundx))
  100.           dx2 = -dx2;
  101.        x2[i] = x2[j] + dx2;
  102.        if ( (y1[j] + dy1 < 0) || (y1[j] + dy1 > boundy))
  103.           dy1 = -dy1;
  104.        y1[i] = y1[j] + dy1;
  105.        if ( (y2[j] + dy2 < 0) || (y2[j] + dy2 > boundy))
  106.           dy2 = -dy2;
  107.        y2[i] = y2[j] + dy2;
  108.        MoveTo(x1[i], y1[i]); /* draw new line */
  109.        LineTo(x2[i], y2[i]);
  110.        i = (i + 1) & size -1; /* get oldest line */
  111.     }
  112. }
  113. /* End of text from uiucdcsb:net.sources.mac */
  114.